<?php

require_once dirname(__FILE__) . '/loadphplib.php';

$arrUniqDomainDataWWW = getArrayFromFile(dirname(__FILE__) . '/domainlist.txt');

$arrUnSetDomains = getArrayFromFile(dirname(dirname(__FILE__)) . '/stat/unsetdomain.txt');

foreach ($arrUniqDomainDataWWW as $domainALL) {
    $arrDInfo = explode('.', $domainALL);
    $length = count($arrDInfo);
    $extk = $length - 1;
    $dok = $length - 2;
    $domain = $arrDInfo[$dok] . '.' . $arrDInfo[$extk];
    if (is_numeric($arrDInfo[$extk])) {
        log::w($domain);
        continue;
    }
    if (in_array($domain, $arrUnSetDomains)) {
        continue;
    }
    if (in_array($domainALL, $arrUnSetDomains)) {
        continue;
    }
    if (in_array(str_replace('www.', '', $domainALL), $arrUnSetDomains)) {
        continue;
    }
    $arrUniqDomainDataUniq[] = $domainALL;
}

sort($arrUniqDomainDataUniq);

$df = glob(dirname(__FILE__) . '/*.domains');
foreach ((array) $df as $f) {
    @unlink($f);
}

$SmallArrays = array_chunk($arrUniqDomainDataUniq, 200);
foreach ($SmallArrays as $k => $arrArrays) {
    file_put_contents(dirname(__FILE__) . '/domain_split_' . $k . '.domains', json_encode($arrArrays));
}
?>